Operator_Compare Method

Used to overload the intrinsic comparison operators, providing custom functionality.

Syntax


Notes

If Operator_Compare is defined, it is called whenever any of the comparison operators are used to compare the Self instance of the class with another instance. The following comparison operators are covered: =, <, >, <=, >=, <>.

Operator_Compare returns an Integer whose meaning is as follows: <0 means that Self is less than the passed parameter, 0 means that Self is equal to the passed parameter, and >0 means that Self is greater than the passed parameter.


Example

This example defines a comparison between two Vectors which have been declared with Integer properties x and y (See Operator_Add). The function compares the square lengths of the vectors and then reports on which one is longer.

Function Operator_Compare(rhs as Vector) as Integer
  Dim a, b as Integer
 a= Self.x^2 + Self.y^2
 b=rhs.x^2 + rhs.y^2

If a>b then Return 1
If a=b then Return 0
If a<b then Return -1

See Also

=, <, >, <=, >=, <> operators.